//
//  SettingVC.m
//  SSC
//
//  Created by 红沙尘 on 17/6/8.
//  Copyright © 2017年 红沙尘. All rights reserved.
//

#import "SettingVC.h"
#import "AppDelegate.h"

@interface SettingVC ()
{
    NSArray *array;
}
@end

@implementation SettingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setTitle:@"设置"];
    
    array = @[@{@"title":@"版本更新",@"image":@"setting_versionupdate"},
              @{@"title":@"清除缓存",@"image":@"setting_deletecache"}];
    mainTableView.rowHeight = 44;
    mainTableView.estimatedRowHeight = 44;
    mainTableView.backgroundColor = ARGB(244, 244, 244, 1);
    
//    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
//    btn.frame = CGRectMake(0, 0, ScreenWidth, 44);
//    btn.backgroundColor = [UIColor whiteColor];
//    btn.titleLabel.font = [MTool fontOfSize:18];
//    [btn setTitle:@"退出登录" forState:UIControlStateNormal];
//    [btn setTitleColor:ARGB(255,82,83,1) forState:UIControlStateNormal];
//    mainTableView.tableFooterView = btn;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return array.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 12;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    if (section == 1) return 36;
    
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SettingCell"];
    
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:@"SettingCell"];
        cell.textLabel.textColor = ARGB(102, 102, 102, 1);
        cell.textLabel.font = [MTool fontOfSize:12];
    }
    
    NSDictionary *dict = array[indexPath.section];
    
    cell.textLabel.text = dict[@"title"];
    cell.imageView.image = LoadImage(dict[@"image"]);
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 0) {
        [self checkedVersion];
        
    } else if (indexPath.section == 1) {
        [MTool showAlertController:self message:@"清理缓存成功！"];
    }
}

- (void)checkedVersion {

    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    
    [app checkVersion];
//    [MTool showMessage:@"当前版本日期2016-06-29 16:55" inView:nil];
//    
//    return;
//    NSString *msg = @"您当前版本较低，请升级为新版本V2.0 ";
//    
//    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@""
//                                                                             message:msg
//                                                                      preferredStyle:UIAlertControllerStyleAlert];
//    
//    [alertController addAction:[UIAlertAction actionWithTitle:@"版本更新"
//                                                        style:UIAlertActionStyleDestructive
//                                                      handler:^(UIAlertAction * _Nonnull action) {
//        
//    }]];
//    
//    [alertController addAction:[UIAlertAction actionWithTitle:@"残忍拒绝"
//                                                        style:UIAlertActionStyleDefault
//                                                      handler:^(UIAlertAction * _Nonnull action) {
//                                                          
//                                                      }]];
//    
//    [self presentViewController:alertController animated:YES completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
